package sixyz.controller;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class OnlineListener implements HttpSessionListener {

    // 在线人数
    private Integer onlineNumber = 0;

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        onlineNumber++;
        // 在context里记录attribute
        se.getSession().getServletContext().setAttribute("onlineNumber", onlineNumber);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        onlineNumber--;
        // 在context里记录attribute
        se.getSession().getServletContext().setAttribute("onlineNumber", onlineNumber);
    }
}
